package com.mrd.gtimp.sup.service;

import com.mrd.base.BaseBiz;
import com.mrd.framework.ui.filter.Filter;
import com.mrd.framework.ui.filter.FilterGroupOption;
import com.mrd.framework.ui.filter.SearchRule;
import com.mrd.framework.ui.filter.SearchRuleOption;
import com.mrd.gtimp.sup.entity.SupCustomerRole;
import com.mrd.spring.repository.BaseRepository;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

import javax.annotation.Resource;

/**
 * <p> application name: gtimp <p> copyright: Copyright@2012 明睿达科技有限公司
 */

/**
 * @author luob
 */
@Service
public class SupCustomerRoleBiz extends BaseBiz<SupCustomerRole> {


    @Resource
    // 该处指定注入BaseRepository的dao对象
    @Qualifier("supCustomerRoleDao")
    public void setBaseRepository(BaseRepository<SupCustomerRole, String> baseRepository) {
        super.baseRepository = baseRepository;
    }


    public SupCustomerRole getDefaultCustomerRole(String comId) throws Exception {
        Filter filters = new Filter();
        filters.setGroupOp(FilterGroupOption.AND);
        filters.addRule(new SearchRule("IS_DEFAULT", SearchRuleOption.eq, "是"));
        filters.addRule(new SearchRule("COM_ID", SearchRuleOption.eq, comId));

        List<SupCustomerRole> resultList = baseRepository.findEntityByFilter(0, 1, filters, null);
        if (null != resultList && resultList.size() >= 1) {
            return resultList.get(0);
        }
        return null;
    }

}
